package com.lanou.lyl.littlebear;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 17/4/12.
 */

public class DbHelper extends SQLiteOpenHelper {

    public static final String DB_NAME = "oil.db";

    public static final String CAR_TABLE_NAME = "cars_tbl";

    public static final String RECORDS_TABLE_NAME = "RECORDS_TBL";

    public static final String _ID = "_id";
    public static final String Car_Name = "name";
    public static final String Car_SELECTED = "selected";
    public static final String Car_MODEL = "model";
    public static final String Car_UUID = "uuid";


    public static final int DB_VERSION = 1;


    public DbHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table if not exists " + CAR_TABLE_NAME + " (" + _ID + " integer primary key autoincrement, " + Car_Name + " text, " + Car_SELECTED + " integer, " + Car_MODEL + " integer, " + Car_UUID + " text)");
        //db.execSQL("create table if not exists " + RECORDS_TABLE_NAME + " (_id integer primary key autoincrement, date text, odometer text, price text, yuan text, type text, gassup text, remark text, carid text, forget text, lightOn text, stationld text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < newVersion) {
            //删除某一个表
            db.execSQL("drop table " + CAR_TABLE_NAME);
            //  db.execSQL("drop table " + RECORDS_TABLE_NAME);
            onCreate(db);
        }
    }


}
